using DynamicProxies;
using DynamicProxies.Tests.InterfaceImplementation;
using DynamicProxies.Tests.Types;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Reflection;
using System.Reflection.Emit;

namespace DynamicProxies.Tests
{
	[TestClass]
	public sealed class IProxyTests : BaseTests
	{
		[TestMethod]
		public void CreateAndVerifyIProxyInterfaceImplementation()
		{
			var simple = new SimpleClass().CreateProxy(
				new ProxyContext(AssemblyBuilderAccess.RunAndSave, true, false), this);
			Assert.IsTrue(typeof(IProxy<SimpleClass>).IsAssignableFrom(simple.GetType()));
			Assert.IsNotNull((simple as IProxy<SimpleClass>).Target);
		}

		[TestMethod, ExpectedException(typeof(ArgumentException))]
		public void CreateWithTypeCorrectlyImplementingIProxy()
		{
			Proxy.Create<BadProxyClassWithCorrectTarget>(this);
		}

		[TestMethod, ExpectedException(typeof(ArgumentException))]
		public void CreateWithTypeIncorrectlyImplementingIProxy()
		{
			Proxy.Create<BadProxyClassWithIncorrectTarget>(this);
		}
	}
}
